package com.czkevin.cif.listeners;

import com.czkevin.cif.CustomItemFramework;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;

public class CIFVanillaActionBlockerListener implements Listener {

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onEnchant(PrepareItemEnchantEvent event) {
        ItemStack item = event.getItem();
        if(CustomItemFramework.isCIFItem(item)) event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onCompleteEnchant(EnchantItemEvent event) {
        ItemStack item = event.getItem();
        if(CustomItemFramework.isCIFItem(item)) event.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onCraft(CraftItemEvent event) {
        ItemStack[] matrix = event.getInventory().getMatrix();
        for(ItemStack i : matrix) {
            if(i == null) continue;
            if(CustomItemFramework.isCIFItem(i)) {
                event.setCancelled(true);
                return;
            }
        }
    }

}
